using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Entities;
using Utility;
namespace BUS
{
  public  class tbKhachhangBUS
    {
        public static void Insert(tbKhachhang kh)
        {
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            khDAL.Insert(kh);
        }
        public static void Update(tbKhachhang kh)
        {
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            khDAL.Update(kh);
        }
        public static void Delete(int iD)
        {
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            khDAL.Delete(iD);
        }
        public static tbKhachhangCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            return khDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbKhachhangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            return khDAL.Get(cri.Criter, 0, 0, tbKhachhangCollumn.makh.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbKhachhang GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbKhachhangCollumn.makh.ToString(), Condition.EQUAL, iD);
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            tbKhachhangCollection khColl = khDAL.Get(cri.Criter, 0, 0, tbKhachhangCollumn.makh.ToString(), OrderDirection.ASC.ToString(), out total);
            if (khColl.Count > 0)
                return khColl[0];
            return null;
        }
        public static tbKhachhangCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            return khDAL.Get(cri.Criter, 1, number,
            tbKhachhangCollumn.makh.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbKhachhangCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            return khDAL.Get(cri.Criter, 1, number,
            tbKhachhangCollumn.makh.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
